﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LotteryVote.Logic;
using LotteryVote.Entity;

namespace LotteryVote
{
    public partial class ShareRateManager : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                BindShareTypes();
        }
        void BindShareTypes()
        {
        }

        protected void btn_addSuper_Click(object sender, EventArgs e)
        {
            ShareRateFacade shareRateFacade = new ShareRateFacade();
            int userId = int.Parse(txt_userId.Text);
            Alert("Success");
        }

        protected void btn_addMaster_Click(object sender, EventArgs e)
        {
            ShareRateFacade shareRateFacade = new ShareRateFacade();
            int userId = int.Parse(txt_userId.Text);
            int parentId = int.Parse(txt_superId.Text);
            Alert("Success");
        }

        protected void btn_addAgent_Click(object sender, EventArgs e)
        {
            ShareRateFacade shareRateFacade = new ShareRateFacade();
            int userId = int.Parse(txt_userId.Text);
            int parentId = int.Parse(txt_masterId.Text);
            Alert("Success");
        }

        void Alert(string message)
        {
            ClientScript.RegisterClientScriptBlock(this.GetType(), Guid.NewGuid().ToString(), string.Format("alert('{0}');", message), true);
        }

        protected void btn_checkShareRate_Click(object sender, EventArgs e)
        {
            ShareRateFacade shareRateFacade = new ShareRateFacade();
            int userId = int.Parse(txt_userId.Text);
            var rateInfo = shareRateFacade.GetShareRateByMember(userId);
            lbl_company.Text = rateInfo.CompanyShareRate.User.UserName + "  " + (rateInfo.CompanyShareRate.ShareRatePercent);
            lbl_super.Text = rateInfo.SuperShareRate.User.UserName + "  " + (rateInfo.SuperShareRate.ShareRatePercent);
            lbl_master.Text = rateInfo.MasterShareRate.User.UserName + "  " + (rateInfo.MasterShareRate.ShareRatePercent);
            lbl_agent.Text = rateInfo.AgentShareRate.User.UserName + "  " + (rateInfo.AgentShareRate.ShareRatePercent);
        }
    }
}